﻿Imports DAO
Imports DTO
Public Class ClopBUS

    Public Function LayDanhSachLop() As List(Of CLopDTO)
        Dim _danhsachlop As New List(Of CLopDTO)
        Dim _dao As New ClopDAO()
        _danhsachlop = _dao.LayDanhSachLop()
        Return _danhsachlop
    End Function

    Public Function LayDanhSachLopcrt() As List(Of CLopCrt)
        Dim _danhsachlop As New List(Of CLopCrt)
        Dim _dao As New ClopDAO()
        _danhsachlop = _dao.LayDanhSachLopcrt()
        Return _danhsachlop
    End Function

    Public Function KiemTraSoLuongLop(ByVal _kldto As CKhoiLopDTO) As Integer
        Dim _dao As New ClopDAO()
        Dim _ds As New List(Of CKhoiLopDTO)
        _ds = _dao.DemSoLuongLop(_kldto)

        If _ds.Count > 0 Then
            If _ds(0).SoLuongLop < _kldto.SoLuongLop Then
                Return 1
            End If
        Else
            Return 1
        End If
        Return 0
    End Function

    Public Function ThemLop(ByVal _lopdto As CLopDTO) As Integer
        Dim _dao As New ClopDAO()
        Dim _kt As Integer = _dao.ThemLop(_lopdto)
        Return _kt
    End Function

    Public Function CapNhatLopCrt(ByVal _lopcrt As CLopCrt) As Integer
        Dim _dao As New ClopDAO()
        Dim _kt As Integer = _dao.CapNhatLopcrt(_lopcrt)
        Return _kt
    End Function

    Public Function CapNhatSiSo(ByVal _lopdto As CLopDTO) As Integer
        Dim _dao As New ClopDAO()
        Dim _bus As New CChiTietLopBUS()
        Dim _kt As Integer
        Dim _ds As New List(Of CChiTietLopCRT)
        _ds = _bus.LaySiSoCbb(_lopdto)

        If _ds.Count > 0 Then
            _lopdto.SiSo = _ds(0).SiSo
            _kt = _dao.CapNhatSiSo(_lopdto)
        Else
            _lopdto.SiSo = 0
            _kt = _dao.CapNhatSiSo(_lopdto)
        End If

        Return _kt
    End Function

    Public Function TraCuuLop(ByVal _TenLop As String) As List(Of CLopCrt)
        Dim _dao As New ClopDAO()
        Dim _dslop As New List(Of CLopCrt)
        _dslop = _dao.TraCuuLop(_TenLop)
        Return _dslop
    End Function
End Class
